
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#include "mex.h"
#include "prefix_tree.h"
#include "path.h"

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, 
  const mxArray *prhs[]) {
    
    tgssmc *trie;
    const int n = 5;
    //unsigned int En[10] = {1,2,3,3,5,6,7,8,9,10};
    unsigned int *En;
    double Tn[10] = {1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0};
    int i, j;
    
    int n_samples = 10;
    path_l *path[20];
    path_el x;
    path_n *node;
    
    srand(time(NULL));
    
    trie = tr_create();
    
    /* Create a path */
    
    
    for (j=0; j<n_samples; j++) {
        path[j] = dll_path_newlist();
        for (i=0; i<n; i++) {
            x.ev_id = (rand() % 5) + 1;
            x.clk = Tn[i];
            x.t_node = NULL;
            node = dll_path_newnode(x);
            dll_path_insertend(path[j], node);
        }
        pt_insert(trie, path[j]);
    }
    
    tr_tofile(trie, "trie.dot");
    
    /*path[0] = dll_path_newlist();
    
    x.ev_id = 1;
    x.clk = 1;
    x.t_node = NULL;
    node = dll_path_newnode(x);
    dll_path_insertend(path[0], node);
    
    x.ev_id = 2;
    x.clk = 2;
    x.t_node = NULL;
    node = dll_path_newnode(x);
    dll_path_insertend(path[0], node);
    
    x.ev_id = 3;
    x.clk = 3;
    x.t_node = NULL;
    node = dll_path_newnode(x);
    dll_path_insertend(path[0], node);
    
    pt_insert(trie, path[0]);
    
    path[1] = dll_path_newlist();
    
    x.ev_id = 1;
    x.clk = 1;
    x.t_node = NULL;
    node = dll_path_newnode(x);
    dll_path_insertend(path[1], node);
    
    x.ev_id = 3;
    x.clk = 2;
    x.t_node = NULL;
    node = dll_path_newnode(x);
    dll_path_insertend(path[1], node);
    
    x.ev_id = 4;
    x.clk = 3;
    x.t_node = NULL;
    node = dll_path_newnode(x);
    dll_path_insertend(path[1], node);
    
    pt_insert(trie, path[1]);
    
    tr_debug(trie);*/
    
    
    /* TODO --- HEREEEEE */
    
    /*En = malloc(sizeof(int)*n);
    
    for (i=0; i<n_samples; i++) {
        mexPrintf("%d.",0);
        for (j=1; j<n; j++) {
            En[j] = (rand() % 5) + 1;
            mexPrintf("%d.", En[j]);
        }
        mexPrintf("\n");
        En[0]=0;
        tr_insert(trie, En, Tn, n);
    }*/
    //tr_debug(trie);
    
    //tr_tofile(trie, "trie.dot");
}
